<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <title>Fluenty Survey</title>
    <style>
      body {
        margin: 0 auto;
        padding: 0;
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans',
          'Helvetica Neue', sans-serif;
        background-color: #fff;
        max-width: 600px;
      }
      .container {
        padding: 20px;
        display: flex;
        flex-direction: column;
        min-height: 100vh;
      }
      .nav-progress-container {
        display: flex;
        align-items: center;
        margin-bottom: 30px;
        gap: 15px;
      }
      .back-button {
        width: 30px;
        height: 30px;
        border: none;
        background: none;
        cursor: pointer;
        color: #2b85e4;
        font-size: 20px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .back-button svg {
        width: 20px;
        height: 20px;
        fill: currentColor;
      }
      .progress-bar {
        flex: 1;
        height: 6px;
        background-color: #e0e0e0;
        border-radius: 3px;
      }
      .progress {
        height: 100%;
        width: 89.91%;
        background-color: #2b85e4;
        border-radius: 3px;
      }
      .title {
        font-size: 36px;
        font-weight: bold;
        color: #0B4983;
        margin-bottom: 30px;
        line-height: 1.3;
        text-align: center;
      }
      .subtitle {
        font-size: 22px;
        font-weight: 500;
        color: #333;
        margin-bottom: 40px;
        text-align: center;
      }
      .occasions-list {
        display: flex;
        flex-direction: column;
        gap: 15px;
        width: 100%;
        max-width: 720px;
        margin: 0 auto 40px;
      }
      .occasion-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 15px 20px;
        border-radius: 16px;
        background-color: white;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        border: 1px solid #e0e0e0;
        cursor: pointer;
        transition: all 0.2s ease;
      }
      .occasion-item:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
      }
      .occasion-icon {
        font-size: 28px;
        margin-right: 15px;
      }
      .occasion-name {
        font-size: 18px;
        font-weight: 500;
        color: #333;
        flex: 1;
      }
      .occasion-left {
        display: flex;
        align-items: center;
      }
      .radio-button {
        width: 22px;
        height: 22px;
        border-radius: 50%;
        border: 2px solid #e0e0e0;
        position: relative;
      }
      .occasion-item.selected .radio-button {
        border-color: #2b85e4;
      }
      .occasion-item.selected .radio-button:after {
        content: '';
        position: absolute;
        width: 12px;
        height: 12px;
        background-color: #2b85e4;
        border-radius: 50%;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
      }
      .continue-button {
        background-color: #3b82f6;
        color: white;
        border: none;
        border-radius: 12px;
        padding: 16px;
        font-size: 18px;
        font-weight: bold;
        width: 100%;
        cursor: pointer;
        text-align: center;
        margin-top: auto;
        margin-bottom: 20px;
        max-width: 720px;
        align-self: center;
      }
      .continue-button:disabled {
        background-color: #94a3b8;
        cursor: not-allowed;
      }
      .continue-button:not(:disabled):hover {
        background-color: #2563eb;
      }
      @media (max-width: 480px) {
        .title {
          font-size: 32px;
        }
        .subtitle {
          font-size: 18px;
        }
        .occasion-name {
          font-size: 16px;
        }
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="nav-progress-container">
        <button class="back-button">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
            <path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z" />
          </svg>
        </button>
        <div class="progress-bar">
          <div class="progress"></div>
        </div>
      </div>

      <h1 class="title">Are there any occasions in your life you'd like to be prepared for?</h1>
      <h2 class="subtitle">The choice won't limit your experience</h2>

      <div class="occasions-list">
        <div class="occasion-item">
          <div class="occasion-left">
            <span class="occasion-icon">💼</span>
            <span class="occasion-name">New job</span>
          </div>
          <div class="radio-button"></div>
        </div>

        <div class="occasion-item">
          <div class="occasion-left">
            <span class="occasion-icon">🏡</span>
            <span class="occasion-name">Moving to a another country</span>
          </div>
          <div class="radio-button"></div>
        </div>

        <div class="occasion-item">
          <div class="occasion-left">
            <span class="occasion-icon">🤝</span>
            <span class="occasion-name">Job interview</span>
          </div>
          <div class="radio-button"></div>
        </div>

        <div class="occasion-item">
          <div class="occasion-left">
            <span class="occasion-icon">📝</span>
            <span class="occasion-name">Exam</span>
          </div>
          <div class="radio-button"></div>
        </div>

        <div class="occasion-item">
          <div class="occasion-left">
            <span class="occasion-icon">🏖️</span>
            <span class="occasion-name">Vacation abroad</span>
          </div>
          <div class="radio-button"></div>
        </div>

        <div class="occasion-item">
          <div class="occasion-left">
            <span class="occasion-icon">🙋‍♂️</span>
            <span class="occasion-name">None of above</span>
          </div>
          <div class="radio-button"></div>
        </div>
      </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const backButton = document.querySelector('.back-button');
            const occasionItems = document.querySelectorAll('.occasion-item');
            let selectedOccasion = null;

            // 从 localStorage 中获取之前保存的选中状态
            const pageName = window.location.pathname.split('/').pop().split('.')[0];
            const storedData = localStorage.getItem(pageName);
            if (storedData) {
                const parsedData = JSON.parse(storedData);
                selectedOccasion = parsedData.occasion;
                occasionItems.forEach(item => {
                    const occasionName = item.querySelector('.occasion-name').textContent;
                    if (occasionName === selectedOccasion) {
                        item.classList.add('selected');
                    }
                });
            }

            // Back button functionality
            backButton.addEventListener('click', function () {
                window.location.href = 'whatPersonal.html';
            });

            // Occasion item selection functionality
            occasionItems.forEach(item => {
                item.addEventListener('click', function () {
                    // Deselect all items
                    occasionItems.forEach(i => i.classList.remove('selected'));

                    // Select current item
                    this.classList.add('selected');

                    const occasionName = this.querySelector('.occasion-name').textContent;
                    selectedOccasion = occasionName;

                    // 获取页面标题和当前页面名称
                    const pageTitle = document.querySelector('.title')
                       ? document.querySelector('.title').textContent.trim()
                        : "Are there any occasions in your life you'd like to be prepared for?";
                    const subtitle = document.querySelector('.subtitle')
                       ? document.querySelector('.subtitle').textContent.trim()
                        : "The choice won't limit your experience";

                    // 创建数据对象
                    const data = {
                        title: pageTitle,
                        subtitle: subtitle,
                        value: selectedOccasion,
                        occasion: selectedOccasion,
                    };

                    // 以 JSON 格式存储到 localStorage
                    localStorage.setItem(pageName, JSON.stringify(data));

                    // 保留原有存储方式，以保证兼容性
                    localStorage.setItem('selectedOccasion', selectedOccasion);

                    // Redirect to eventPlan.html
                    window.location.href = 'eventPlan.html';
                });
            });
        });
    </script>
  </body>
</html>
